<include file="public@header" />
</head>
<body>
	<div class="wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:url('AdminIndex/index')}">{:lang('TENANT_USER')}</a></li>
			<li class="active"><a href="{:url('AdminIndex/add')}">新增{:lang('TENANT_USER')}</a></li>
		</ul>
        <form method="post" class="form-horizontal is-ajax-form margin-top-20" action="{:url('AdminIndex/addpost')}">
			<div class="form-group">
				<label for="input-user_login" class="col-sm-2 control-label"><span class="form-required">*</span>{:lang('USERNAME')}</label>
				<div class="col-md-6 col-sm-10">
					<input type="text" class="form-control" id="input-name" name="post[name]" required>
				</div>
            </div>
            <div class="form-group">
				<label for="input-user_login" class="col-sm-2 control-label"><span class="form-required">*</span>年龄</label>
				<div class="col-md-6 col-sm-10">
					<input type="text" class="form-control" id="input-age" name="post[age]" required>
				</div>
            </div>
            <div class="form-group">
				<label for="input-user_pass" class="col-sm-2 control-label"><span class="form-required">*</span>性别</label>
				<div class="col-md-6 col-sm-10">
					<input type="radio"  id="input-sex" name="post[sex]" value='0' checked>女
					<input type="radio"  id="input-sex" name="post[sex]" value='1'>男
				</div>
			</div>
            <div class="form-group">
				<label for="input-user_login" class="col-sm-2 control-label"><span class="form-required">*</span>电话</label>
				<div class="col-md-6 col-sm-10">
					<input type="text" class="form-control" id="input-tel" name="post[tel]" required>
				</div>
            </div>
            <div class="form-group">
				<label for="input-user_login" class="col-sm-2 control-label">微信号</label>
				<div class="col-md-6 col-sm-10">
					<input type="text" class="form-control" id="input-wechat_id" name="post[wechat_id]">
				</div>
            </div>
			
			<div class="form-group">
				<label for="input-user_email" class="col-sm-2 control-label"><span class="form-required">*</span>地区</label>
				<div class="col-md-6 col-sm-10">
					<select class="form-control" style="width: 150px;float: left;" name="post[province]" lay-verify="required" lay-search="" onchange="getCity(this.options[this.options.selectedIndex].value,this.options[this.options.selectedIndex].text)">
                        <option value="">请选择 省</option>
                        <foreach name="province" item="vo">
                            <option value="{$vo.id}" name="{$vo.name}">{$vo.name}</option>
                        </foreach>
                      </select>
                      <select class="form-control" style="width: 150px;float: left;" name="post[city]" lay-verify="required" lay-search="" onchange="getCountry(this.options[this.options.selectedIndex].value,this.options[this.options.selectedIndex].text)" id='choseCity'>
                        <option value="" >请选择 市县</option>
                        
                      </select>
                      <select class="form-control" style="width: 150px;float: left;" name="post[country]" lay-verify="required" lay-search="" id='choseCountry' onchange="country(this.options[this.options.selectedIndex].text)">
                        <option value="" >请选择 地区</option>
                        
                      </select>
				</div>
            </div>
            <div class="form-group">
				<label for="input-user_email" class="col-sm-2 control-label"><span class="form-required">*</span>标签</label>
				<div class="col-md-6 col-sm-10">
					<!-- <select class="form-control" name="post[tag_id]" lay-verify="required" lay-search="" >
                        <option value="0">请选择 标签</option>
                        
                      </select> -->
                      <tr id="parts2" style="height: 71px;">
                        <td class="form-inline">
                            <a style="display: none;" id="counter" data-value="1"></a>
                            <div class="col-md-12 col-sm-12 parts">
                                <button type="button" class="layui-btn layui-btn-normal  layui-btn-sm" onclick="addInput();" style="height: 34px; float: left;">添加标签</button>
                                
                            </div>
                            
                        </td>
                    </tr>
				</div>
            </div>
            <div class="form-group">
				<label for="input-user_email" class="col-sm-2 control-label"><span class="form-required">*</span>分类</label>
				<div class="col-md-6 col-sm-10">
					<select class="form-control" name="post[category_id]" lay-verify="required" lay-search="" >
                        <option value="0">请选择 分类</option>
                        <foreach name="category" item="ca">
                            <option value="{$ca.id}">{$ca.name}</option>
                        </foreach>
                      </select>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
                    <input class="form-control" type="hidden" id="province_name" name="post[province_name]" value="">
                        <input class="form-control" type="hidden"  id="city_name" name="post[city_name]" value="">
                        <input class="form-control" type="hidden"  id="country_name" name="post[country_name]" value="">
                    <input type="hidden" name="post[tenant_id]" value="{$tenant_id}"/>
                    <a style="display: none;" id="counter" data-value="0"></a>
					<button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
				</div>
			</div>
		</form>
	</div>
    <script src="__STATIC__/js/admin.js"></script>
    <script type="text/javascript">
        function getCity(province_id,province_name){
            console.log('getCity'+province_id,province_name)
            $("#province_name").attr("value", province_name)
            $.ajax({
                type: "GET",
                url:"{:url('Index/getCity')}",
                data:{
                    province_id:province_id
                },
                success:function(res){
                    console.log(res)
                    if(res['code']==1){
                        $("#choseCity").html('<option value="" >请选择 市县</option>')
    
                        var html = '',city=res['city'];
                        for(var i in city){
                            html+='<option value="'+city[i]['id']+'" name='+city[i]['name']+'>'+city[i]['name']+'</option>'
                        }
                        
                        $("#choseCity").append(html)
                        $("#choseCountry").html('<option value="" >请选择 地区</option>')
                    }
                }
            })
        }
        function getCountry(city_id,city_name){
            $("#city_name").attr("value", city_name)
    
            $.ajax({
                type: "GET",
                url:"{:url('Index/getCountry')}",
                data:{
                    city_id:city_id
                },
                success:function(res){
                    console.log(res)
                    if(res['code']==1){
                        $("#choseCountry").html('<option value="" >请选择 地区</option>')
    
                        var html = '',county=res['county'];
                        for(var i in county){
                            html+='<option value="'+county[i]['id']+'" name="'+county[i]['name']+'">'+county[i]['name']+'</option>'
                        }
                        $("#choseCountry").append(html)
                    }
                }
            })
        }
    
        function country(country_name){
            $("#country_name").attr("value", country_name)
        }

        
    function remove(id){
        var counter = $('#counter').attr('data-value')
        counter--;
        $('#counter').attr('data-value',counter)
        $("#tag_id"+id).remove();
    }
    function addInput(){
        var counter = $('#counter').attr('data-value')
        console.log($(".parts"));
        var node = $(".parts")[0].firstChild;
        var html = '<div style="width:110px;float:left;" id="tag_id'+counter+'" ><input class="form-control"  type="text" style="width:110px;float:left;" value="" name="tag_id[]" required placeholder="标签名" /><i class="fa fa-close" style="position: relative;left: 94px;bottom: 36px;" onclick="remove('+counter+')"></i></div>'
        $(".parts").append(html)
        counter++;
        $('#counter').attr('data-value',counter)
    }
    function showPart() {
        var val = $("input[name='post[parts_mode]']:checked").val()
        console.log(val)
        if(val==2){
            $("#parts").css('display','')
            $("#parts2").css('display','none')
        }else if(val==1){
            $("#parts2").css('display','')

            $("#parts").css('display','none')
        }else{
            $("#parts2").css('display','none')

            $("#parts").css('display','none')
        }

    }

    </script>    
</body>
</html>